/**
 * Created on 2007-05-24 10:42
 */
package game;

import game.score.ScoreManager;

import java.util.HashMap;

/**
 * @author David Wallin
 */
public class Settings
{
	public enum DifficultyLevels
	{
		EASY,
		MEDIUM,
		HARD
	}
	
	public static final Settings												INSTANCE = new Settings();
	
	private boolean																m_SoundOn;
	private boolean																m_ReversedFlip;
	//private boolean						m_HelpTextsOn;
	
	private DifficultyLevels													m_Difficulty;
	
	private final int															INITIAL_BLOCK_DROP_INTERVAL_EASY = 2000;
	private final int															INITIAL_BLOCK_DROP_INTERVAL_MEDIUM = 700;
	private final int															INITIAL_BLOCK_DROP_INTERVAL_HARD = 400;
	
	private final int															FACTOR_EASY = 30;
	private final int															FACTOR_MEDIUM = 50;
	private final int															FACTOR_HARD = 70;
	
	private final HashMap<DifficultyLevels, BlockDropIntervalCalculator>		m_BlockDropIntervalCalculators;
	private ScoreManager														m_ScoreManager = ScoreManager.INSTANCE;
	
	/**
	 * @return the m_HelpTextsOn
	 */
	//public boolean getHelpTextsOn()
	{
		//return m_HelpTextsOn;
	}
	
	public int getBlockDropInterval()
	{
		return m_BlockDropIntervalCalculators.get(m_Difficulty).getBlockDropInterval();
	}
	
	/**
	 * @return the m_ReversedFlip
	 */
	public boolean getReversedFlip()
	{
		return m_ReversedFlip;
	}
	
	/**
	 * @return the m_SoundOn
	 */
	public boolean getSoundOn()
	{
		return m_SoundOn;
	}
	
	/**
	 * @return the m_Difficulty
	 */
	public DifficultyLevels getDifficulty()
	{
		return m_Difficulty;
	}
	
	/**
	 * @param helpTextsOn the m_HelpTextsOn to set
	 */
	//public void setHelpTextsOn(boolean helpTextsOn)
	{
		//m_HelpTextsOn = helpTextsOn;
	}
	
	/**
	 * @param reversedFlip the m_ReversedFlip to set
	 */
	public void setReversedFlip(boolean reversedFlip)
	{
		m_ReversedFlip = reversedFlip;
	}
	
	/**
	 * @param soundOn the m_SoundOn to set
	 */
	public void setSoundOn(boolean soundOn)
	{
		m_SoundOn = soundOn;
	}
	
	/**
	 * @param difficulty the m_Difficulty to set
	 */
	public void setDifficulty(DifficultyLevels difficulty)
	{
		m_Difficulty = difficulty;
	}
	
	/**
	 * Constructor, initializes members
	 */
	private Settings()
	{
		m_SoundOn = true;
		m_ReversedFlip = false;
		//m_HelpTextsOn = true;
		
		m_Difficulty = DifficultyLevels.MEDIUM;
		
		m_BlockDropIntervalCalculators = new HashMap<DifficultyLevels, BlockDropIntervalCalculator>();
		m_BlockDropIntervalCalculators.put(DifficultyLevels.EASY, new BlockDropIntervalCalculator(INITIAL_BLOCK_DROP_INTERVAL_EASY, FACTOR_EASY));
		m_BlockDropIntervalCalculators.put(DifficultyLevels.MEDIUM, new BlockDropIntervalCalculator(INITIAL_BLOCK_DROP_INTERVAL_MEDIUM, FACTOR_MEDIUM));
		m_BlockDropIntervalCalculators.put(DifficultyLevels.HARD, new BlockDropIntervalCalculator(INITIAL_BLOCK_DROP_INTERVAL_HARD, FACTOR_HARD));
	}
	
	private class BlockDropIntervalCalculator
	{
		private int		m_InitialInterval;
		private int		m_Factor;
		
		public BlockDropIntervalCalculator(int initialInterval, int factor)
		{
			m_InitialInterval = initialInterval;
			m_Factor = factor;
		}
		
		public int getBlockDropInterval()
		{
			return m_InitialInterval - (m_ScoreManager.getLevel() * m_Factor);
		}
	}
}
